package com.zff.rental.service;

import com.zff.rental.repository.user.AdministratorRepository;
import com.zff.rental.tools.UserContextHolder;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author HCY
 */
@Service
public class AdminService {
    /**
     * 管理员
     */
    @Resource
    protected AdministratorRepository administratorRepository;

    /**
     * 判断是否是管理员
     *
     * @return boolean
     */
    public boolean isAdmin() {
        return isAdmin(UserContextHolder.getUserId());
    }

    /**
     * 判断是否是管理员
     *
     * @param userId 用户ID
     * @return boolean
     */
    public boolean isAdmin(Long userId) {
        if (userId == null) {
            return false;
        }
        return administratorRepository.isAdmin(userId);
    }

}
